class Query_info

	attr_accessor :master_server,:single_server

	@master_server
	@single_server
	
	def initialize
	end
end

class GameInfo
	
	attr_accessor :name,:mod,:icon,:master_name,:master_address,:master_protocol,:working_dir,:comand_name,:command_flags,:cfg_path,:game_notes,:colour_xml,:query_info
	
	#generic info
	@name
	@mod
	@icon
	@master_name
	@master_address
	@master_protocol
	
	#instalation details
	@working_dir
	@comand_name
	@command_flags
	@cfg_path
	
	#extra
	@game_notes
	@colour_xml
	
	@query_info

	def initialize()
	
	end
end

class ReadXML
	require 'rubygems'
	require 'rexml/document'

	@games_file
	@game_Array
	
	def initialize()
		file = open("games.xml","r");
		@games_file = REXML::Document.new(file.read())
	end
	
	def print_games()
		puts @games_file
	end
		
	def print_game_array()
		@game_Array.each {|game| puts game.name}
	end
	
	def generate_objects
		 @game_Array = Array.new
		 
		 nos = "games/game"
	 
		 @games_file.elements.each(nos) do |elemento|
        
		 game = GameInfo.new 
 
         game.name = elemento.text("name")
		 game.mod = elemento.text("mod")
		 game.icon = elemento.text("icon")
		 game.master_name = elemento.text("masterName")
		 game.master_address = elemento.text("masterAddres")
		 game.master_protocol = elemento.text("masterProtocol")
		 game.working_dir = elemento.text("workingDir")
		 game.comand_name = elemento.text("commandName")
		 game.command_flags = elemento.text("commandFlags")
		 game.cfg_path = elemento.text("cfgPath")
 		 game.colour_xml = elemento.text("colourList")
		 game.game_notes = elemento.text("notes")
		 
		 game.query_info = Query_info.new
		 
		 game.query_info.master_server = elemento.text("query/masterServer")
		 game.query_info.single_server = elemento.text("query/singleServer")
		 
		 print game.query_info.master_server 
		 		 
         @game_Array << game
      end
	
	end
end


xml = ReadXML.new()
xml.print_games 
xml.generate_objects
xml.print_game_array
